"""
des: QuickReName about界面
author: mr_52hz
date: 2021-01-29
"""
import sys

from PyQt5 import QtGui
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor, QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QPushButton, QHBoxLayout

import settings


class HelpWidget(QWidget):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.x = kwargs.get('x', 200)
        self.y = kwargs.get('y', 200)
        self.initUi()

    def initUi(self):
        self.setTop()
        self.setFixedSize(400, 200)
        self.move(self.x, self.y)

        palette1 = QtGui.QPalette()
        # palette1.setBrush(w.backgroundRole(), QtGui.QBrush(image)) #背景图片
        palette1.setColor(self.backgroundRole(), QColor(192, 192, 192))  # 背景颜色
        self.setPalette(palette1)

        help_layout = QVBoxLayout()
        help_lb = QLabel()
        help_lb.setText('<ol><li><p><span>支持多次预览再执行</span></p></li>'
                        '<li><p><span>重名文件自动添加(数字)后缀</span></p></li>'
                        '<li><p><span>支持RE语法 \w、\s、[] ...</span></p></li>'
                        '<li><p><span><a href="https://gitee.com/Mr_52Hz/quick-re-name">more</a></span></p></li>'
                        '</ol>')
        help_lb.setOpenExternalLinks(True)

        btn_layout = QHBoxLayout()
        close_btn = QPushButton()
        close_btn.setFixedSize(settings.BTN_WIDTH, settings.BTN_HEIGHT)
        close_btn.setText('关闭')
        close_btn.pressed.connect(self.close)

        help_layout.addWidget(help_lb)
        btn_layout.addStretch(1)
        btn_layout.addWidget(close_btn)
        btn_layout.addStretch(1)
        help_layout.addLayout(btn_layout)
        self.setLayout(help_layout)

    def setTop(self):
        # 去除标题 图标等 仅保留窗口 & 设置为顶层窗口
        self.setWindowFlags(Qt.FramelessWindowHint)
        # 阻塞父类窗口不能点击
        self.setWindowModality(Qt.ApplicationModal)


class AboutWidget(QWidget):

    def __init__(self, parent=None, *args, **kwargs):
        self.icon_path = kwargs.get('icon', settings.BASE_DIR + '/UI/qss/icon.png')
        # 额外参数调用super导致闪退
        kwargs.pop('icon')

        super().__init__(parent, *args, **kwargs)
        self.x = kwargs.get('x', 200)
        self.y = kwargs.get('y', 200)
        self.initUi()

    def initUi(self):
        self.setTop()
        self.setFixedSize(400, 200)
        self.move(self.x, self.y)

        palette1 = QtGui.QPalette()
        # palette1.setBrush(w.backgroundRole(), QtGui.QBrush(image)) #背景图片
        palette1.setColor(self.backgroundRole(), QColor(192, 192, 192))  # 背景颜色
        self.setPalette(palette1)

        brand_icon_lb = QLabel()
        brand_icon_lb.setFixedSize(128, 128)
        brand_icon_lb.setPixmap(QPixmap(self.icon_path))
        brand_icon_lb.setScaledContents(True)
        version_lb = QLabel('<p><font style="">QuickRename %s</font></p>'
                            % settings.VERSION)
        home_link = QLabel('<p>Home: <a href="https://gitee.com/Mr_52Hz/quick-re-name">gitee仓库</a></p>')
        home_link.setOpenExternalLinks(True)
        author_lb = QLabel('<p>Author: <font style="color: blue">%s</font></p>' % settings.AUTHOR)

        about_layout = QVBoxLayout()
        about_layout.setAlignment(Qt.AlignHCenter)

        text_msg_layout = QVBoxLayout()
        text_msg_layout.setContentsMargins(0, 20, 0, 10)
        all_msg_layout = QHBoxLayout()
        btn_layout = QHBoxLayout()

        close_btn = QPushButton()
        close_btn.setFixedSize(settings.BTN_WIDTH, settings.BTN_HEIGHT)
        close_btn.setText('关闭')
        close_btn.pressed.connect(self.close)

        all_msg_layout.addStretch(1)
        all_msg_layout.addWidget(brand_icon_lb)
        text_msg_layout.addWidget(home_link)
        text_msg_layout.addWidget(version_lb)
        text_msg_layout.addWidget(author_lb)
        all_msg_layout.addSpacing(20)
        all_msg_layout.addLayout(text_msg_layout)
        all_msg_layout.addStretch(1)
        about_layout.addLayout(all_msg_layout)
        btn_layout.addStretch(1)
        btn_layout.addWidget(close_btn)
        btn_layout.addStretch(1)
        about_layout.addLayout(btn_layout)
        self.setLayout(about_layout)

    def setTop(self):
        # 去除标题 图标等 仅保留窗口 & 设置为顶层窗口
        self.setWindowFlags(Qt.FramelessWindowHint)
        # 阻塞父类窗口不能点击
        self.setWindowModality(Qt.ApplicationModal)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    about = HelpWidget()
    about.show()
    sys.exit(app.exec())
